package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.subsidyapplicationpayrecord.LindiSubsidyApplicationPayRecordQueryVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplicationpayrecord.LindiSubsidyApplicationPayRecordVO;
import com.minimalist.common.feign.client.lindi.LindiSubsidyApplicationPayRecordFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地指标交易平台_补贴申请支付记录Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author 11987
 */
@Component
public class LindiSubsidyApplicationPayRecordFeignClientFallbackFactory extends BaseFallbackFactory<LindiSubsidyApplicationPayRecordFeignClient> {

    private static final Logger log = LoggerFactory.getLogger(LindiSubsidyApplicationPayRecordFeignClientFallbackFactory.class);

    @Override
    public LindiSubsidyApplicationPayRecordFeignClient create(Throwable cause) {
        return new LindiSubsidyApplicationPayRecordFeignClient() {
            @Override
            public R<?> addSubsidyApplicationPayRecord(LindiSubsidyApplicationPayRecordVO subsidyApplicationPayRecordVO) {
                logServiceUnavailable("添加补贴申请支付记录", subsidyApplicationPayRecordVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加补贴申请支付记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteSubsidyApplicationPayRecordBySubsidyApplicationPayRecordId(Long subsidyApplicationPayRecordId) {
                logServiceUnavailable("删除补贴申请支付记录", subsidyApplicationPayRecordId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除补贴申请支付记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateSubsidyApplicationPayRecordBySubsidyApplicationPayRecordId(LindiSubsidyApplicationPayRecordVO subsidyApplicationPayRecordVO) {
                logServiceUnavailable("修改补贴申请支付记录", subsidyApplicationPayRecordVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改补贴申请支付记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiSubsidyApplicationPayRecordVO>> getPageSubsidyApplicationPayRecordList(LindiSubsidyApplicationPayRecordQueryVO queryVO) {
                logServiceUnavailable("分页查询补贴申请支付记录列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询补贴申请支付记录列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiSubsidyApplicationPayRecordVO> getSubsidyApplicationPayRecordBySubsidyApplicationPayRecordId(Long subsidyApplicationPayRecordId) {
                logServiceUnavailable("根据ID查询补贴申请支付记录", subsidyApplicationPayRecordId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据ID查询补贴申请支付记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiSubsidyApplicationPayRecordVO>> getSubsidyApplicationPayRecordListBySubsidyApplicationId(Long subsidyApplicationId) {
                logServiceUnavailable("根据补贴申请ID查询支付记录列表", subsidyApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据补贴申请ID查询支付记录列表失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}